; *** Swappers
; *** Copyright 1998-2002 Zillions Development
; v.2.0

; You need to purchase Zillions of Games to load this rules file
; Visit the Zillions web site at http://www.zillions-of-games.com
(translate
 ("2 and 2" "2子交换") ("3 and 3" "3子交换") ("4 and 4" "4子交换") ("5 and 5" "5子交换")
 ("Big Swap" "上下交换") ("Fore and Aft" "对角交换")
 ("TriColor" "三色E字")
)
(define slide-or-jump (
	$1
	(if empty? add
	 else (verify (empty? $1)) $1 add
	)
))
(define blue-slide-or-jump (
	b
	(if empty? add
	 else (verify (piece? Green)) (verify (empty? b)) b add
	)
))
(define green-slide-or-jump (
	g
	(if empty? add
	 else (verify (piece? Blue)) (verify (empty? g)) g add
	)
))

(define far-slide
	(if (empty? $1)
		(while (empty? $1)
		   $1
		   (if (empty? in) in add (opposite in))
		)
		(if (not-empty? in) add)
	)
)
(define far-slides (
	(if (empty? (opposite in))
		(opposite in)
		(if (not (or (empty? blue-dir) (empty? green-dir)))
			add
			(verify false)
		)
		mark
	)
	(far-slide blue-dir)
	back
	(far-slide green-dir)
))

; ************************************************************************
(game
    (title "2 and 2")
	(solution "Solutions\Swappers\2_and_2.zsg")
    (description "球可以移动至相邻空位，或跳过不同颜色的球到其后一格。\蓝色球只能向右移动，绿色球只能向左移动。\\本关目标：交换两组球位置。目标位置在棋盘上有颜色标记。\最佳解法：8步")
    (history "This is a puzzle that's often played with two sets of different
	    coins.  Maxey Brooke describes it in his book `Coin Games and Puzzles`
		but says he has found it as a chess puzzle in a book dated 1882.")
    (strategy "Avoid two marbles of the same color in a row and try to alternate
		marbles instead.  There is only one winning strategy and that is the
        key to it.   If you can work out the 2 and 2 case, the bigger games
        should follow.  To see the solution, select `Show Solution`
	    under the Help menu.")
    (option "prevent flipping" true)
    (move-sound "Audio\\Clack.wav")
    (click-sound "Audio\\Tink.wav")
    (release-sound "Audio\\Clack.wav")
    (players Player)
    (turn-order Player)
	(board
        (image "images\Solitaire\2and2Bd.bmp")
        (grid
            (start-rectangle 6 6 36 36) ; top-left position
            (dimensions
                ("a/b/c/d/e" (38 0)) ; columns
                ("1" (0 38)) ; rows
			)
			(directions (b 1 0) (g -1 0))
		)
	)
    (piece
        (name Blue)
        (image Player "images\Solitaire\Marble.bmp")
		(help "只能向右侧移动，可跳过不同色的球至相邻空格")
		(moves (blue-slide-or-jump))			
	)
    (piece
        (name Green)
        (image Player "images\Solitaire\GreenMarble.bmp")
		(help "只能向左侧移动，可跳过不同色的球至相邻空格")
		(moves (green-slide-or-jump))			
	)
    (board-setup
        (Player
		   (Blue  a1 b1)
		   (Green d1 e1)
		)
	)
    (win-condition (Player)
		(and
		   (absolute-config Blue  (d1 e1))
		   (absolute-config Green (a1 b1))
		)
	)
)

(variant
    (title "3 and 3")
	(solution "Solutions\Swappers\3_and_3.zsg")
    (description "球可以移动至相邻空位，或跳过不同颜色的球到其后一格。\蓝色球只能向上或向右移动，绿色球只能向上或向左移动。\\本关目标：交换两组球位置。目标位置在棋盘上有颜色标记。\最佳解法：15步")
    (board
        (image "images\Solitaire\3and3Bd.bmp")
        (grid
            (start-rectangle 6 6 36 36) ; top-left position
            (dimensions
                ("a/b/c/d/e" (38 0)) ; columns
                ("2/1" (0 38)) ; rows
			)
			(directions (b 1 0) (g -1 0))
		)
		(kill-positions b1 c1 d1)
		(links b (a1 a2) (e2 e1))
		(links g (a2 a1) (e1 e2))
	)
    (board-setup
        (Player
		   (Blue  a1 a2 b2)
		   (Green d2 e2 e1)
		)
	)
    (win-condition (Player)
		(and
		   (absolute-config Blue  (d2 e2 e1))
		   (absolute-config Green (a1 a2 b2))
		)
	)
)

(variant
    (title "4 and 4")
	(solution "Solutions\Swappers\4_and_4.zsg")
    (description "球可以移动至相邻空位，或跳过不同颜色的球到其后一格。\蓝色球只能向上或向右移动，绿色球只能向上或向左移动。\\本关目标：交换两组球位置。目标位置在棋盘上有颜色标记。最佳解法：24步")
    (board
        (image "images\Solitaire\4and4Bd.bmp")
        (grid
            (start-rectangle 6 6 36 36) ; top-left position
            (dimensions
                ("a/b/c/d/e" (38 0)) ; columns
                ("3/2/1" (0 38)) ; rows
			)
			(directions (b 1 0) (g -1 0))
		)
		(kill-positions b1 c1 d1 b2 c2 d2)
		(links b (a1 a2) (a2 a3) (e3 e2) (e2 e1))
		(links g (a2 a1) (a3 a2) (e2 e3) (e1 e2))
	)
    (board-setup
        (Player
		   (Blue  a1 a2 a3 b3)
		   (Green d3 e3 e2 e1)
		)
	)
    (win-condition (Player)
		(and
		   (absolute-config Blue  (d3 e3 e2 e1))
		   (absolute-config Green (a1 a2 a3 b3))
		)
	)
)

(variant
    (title "5 and 5")
	(solution "Solutions\Swappers\5_and_5.zsg")
    (description "球可以移动至相邻空位，或跳过不同颜色的球到其后一格。\蓝色球只能向上或向右移动，绿色球只能向上或向左移动。\\本关目标：交换两组球位置。目标位置在棋盘上有颜色标记。\最佳解法：35步")
    (board
        (image "images\Solitaire\5and5Bd.bmp")
        (grid
            (start-rectangle 6 6 36 36) ; top-left position
            (dimensions
                ("a/b/c/d/e" (38 0)) ; columns
                ("4/3/2/1" (0 38)) ; rows
			)
			(directions (b 1 0) (g -1 0))
		)
		(kill-positions b1 c1 d1 b2 c2 d2 b3 c3 d3)
		(links b (a1 a2) (a2 a3) (a3 a4) (e4 e3) (e3 e2) (e2 e1))
		(links g (a2 a1) (a3 a2) (a4 a3) (e3 e4) (e2 e3) (e1 e2))
	)
    (board-setup
        (Player
		   (Blue  a1 a2 a3 a4 b4)
		   (Green d4 e4 e3 e2 e1)
		)
	)
    (win-condition (Player)
		(and
		   (absolute-config Blue  (d4 e4 e3 e2 e1))
		   (absolute-config Green (a1 a2 a3 a4 b4))
		)
	)
)

(variant (title "-")) ; -----------------------------------------------------------------

(variant
    (title "Big Swap")
	(solution "Solutions\Swappers\Big_Swap.zsg")
    (description "球可以移动至相邻空位，或跳过不同颜色的球到其后一格。\蓝色球只能向上或向左右移动，绿色球只能向上或向左右移动。\\本关目标：交换两组球位置。目标位置在棋盘上有颜色标记。")
    (strategy "The solution is long, but not hard if you break it into
	    steps.\\Hint: Start by transposing the marbles in the middle column.  If
	    you've mastered the earlier Swappers puzzles this step should be a
	    piece of cake.   Then begin transposing the middle row of marbles, one
        step at a time, using the gap created at each step to transpose another
        column of marbles.\\To see a solution, select `Show Solution`
	    under the Help menu.")
    (history "This puzzle appears in `Puzzles Old and New`, by Professor Hoffman,
          published in 1893.   It is a two-dimensional derivation of the simple one-row
          swappers above.")
    (board
        (image "images\Solitaire\5x7Bd.bmp")
        (grid
            (start-rectangle 6 6 36 36) ; top-left position
            (dimensions ;5x7
                ("a/b/c/d/e" (38 0)) ; columns
                ("7/6/5/4/3/2/1" (0 38)) ; rows
			)
			(directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0))
		)
    )
    (piece
        (name Blue)
		(help "蓝球可以向左右或向下移动，可跳过不同色的球至相邻空格")
		(description "蓝色\可以向左右或向下移动，可跳过不同色的球至相邻空格")
        (image Player "images\Solitaire\Marble.bmp")
		(moves (slide-or-jump s) (slide-or-jump e) (slide-or-jump w))			
	)
    (piece
        (name Green)
		(help "绿球可以向左右或向上移动，可跳过不同色的球至相邻空格")
		(description "绿球\可以向左右或向上移动，可跳过不同色的球至相邻空格")
        (image Player "images\Solitaire\GreenMarble.bmp")
		(moves (slide-or-jump n) (slide-or-jump e) (slide-or-jump w))			
	)
            
    (board-setup
        (Player
		   (Blue  a7 b7 c7 d7 e7 a6 b6 c6 d6 e6 a5 b5 c5 d5 e5 a4 b4)
		   (Green a1 b1 c1 d1 e1 a2 b2 c2 d2 e2 a3 b3 c3 d3 e3 d4 e4)
		)
	)
    (win-condition (Player)
		(and
		   (absolute-config Blue  (a1 b1 c1 d1 e1 a2 b2 c2 d2 e2 a3 b3 c3 d3 e3 d4 e4))
		   (absolute-config Green (a7 b7 c7 d7 e7 a6 b6 c6 d6 e6 a5 b5 c5 d5 e5 a4 b4))
		)
	)
)

(variant
    (title "Fore and Aft")
	(solution "Solutions\Swappers\Fore_and_Aft.zsg")
    (description "球可以移动至相邻空位，或跳过不同颜色的球到其后一格。\蓝色球只能向下或向左移动，绿色球只能向上或向右移动。\\本关目标：交换两组球位置。目标位置在棋盘上有颜色标记。")
    (strategy "Always move your marbles towards their goals and try to make
	    as many leaps as possible.  This cuts down the number of moves.\\To
		see a solution, select `Show Solution` under the Help menu.")
    (history "Famous puzzler Sam Loyd (1841-1911) wrote of a English sailor
	    on Staten Island who `...used to pick up quite a little bit of extra
		baccy silver, as he termed it, by selling the puzzles to visitors as
		fast as he could whittle them out with a jack-knife.  The game was
		brought out in London and enjoyed quite a run under the name of the
		English Sixteen Puzzle, but was never marketed on this side of the pond.`
            The minimal solution of 46 moves was discovered by H.E. Dudeney.")
    (board
        (image "images\Solitaire\16MarblesBd.bmp")
        (grid
            (start-rectangle 6 6 36 36) ; top-left position
            (dimensions ;5x5
                ("a/b/c/d/e" (38 0)) ; columns
                ("5/4/3/2/1" (0 38)) ; rows
			)
			(directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0))
		)
		(kill-positions a1 a2 b1 b2 d4 d5 e4 e5)
	)
    (piece
        (name Blue)
		(help "蓝球可以向右或向下移动，可跳过不同色的球至相邻空格")
		(description "蓝色\可以向右或向下移动，可跳过不同色的球至相邻空格")
        (image Player "images\Solitaire\Marble.bmp")
		(moves (slide-or-jump e) (slide-or-jump s))			
	)
    (piece
        (name Green)
		(help "绿球可以向左或向上移动，可跳过不同色的球至相邻空格")
		(description "绿球\可以向左或向上移动，可跳过不同色的球至相邻空格")
        (image Player "images\Solitaire\GreenMarble.bmp")
		(moves (slide-or-jump n) (slide-or-jump w))			
	)
            
    (board-setup
        (Player
		   (Blue  a5 b5 c5 a4 b4 c4 a3 b3)
		   (Green d3 e3 c2 d2 e2 c1 d1 e1)
		)
	)
    (win-condition (Player)
		(and
		   (absolute-config Blue  (d3 e3 c2 d2 e2 c1 d1 e1))
		   (absolute-config Green (a5 b5 c5 a4 b4 c4 a3 b3))
		)
	)
)


(variant (title "-")) ; -----------------------------------------------------------------

(define 2D-defs
    (strategy "Use the nooks as temporary holding spots for marbles.  Try to
        think ahead and get your marbles in one by one.\\To see a solution, select
	    `Show Solution` under the Help menu.")
    (piece
        (name Blue)
        (image Player "images\Solitaire\Marble.bmp")
		(help "球必须沿横或竖方向无限移动至撞到什么东西为止。可以转弯。")
		(moves (far-slides))			
	)
    (piece
        (name Green)
        (image Player "images\Solitaire\GreenMarble.bmp")
		(help "球必须沿横或竖方向无限移动至撞到什么东西为止。可以转弯。")
		(moves (far-slides))			
	)
)

(variant
    (title "Pi")
    (solution "Solutions\Swappers\Pi.zsg")
    (description "球可以任意移动，但不能越过其他子，且必须在撞墙或撞到其他子后停止。\\本关目标：交换两组球位置。目标位置在棋盘上有颜色标记。")
    (history "") ;###
    (2D-defs)
    (board
        (image "images\Solitaire\PiBd.bmp")
        (grid
            (start-rectangle 6 6 36 36) ; top-left position
            (dimensions
                ("a/b/c/d/e" (38 0)) ; columns
                ("4/3/2/1" (0 38)) ; rows
			)
		)
		(kill-positions a1 a2 a3 c1 c2 c3 e1 e2 e3)
		(links blue-dir  (b1 b2) (b2 b3) (b3 b4) (b4 c4) (c4 d4) (d4 d3) (d3 d2) (d2 d1))
		(links green-dir (b2 b1) (b3 b2) (b4 b3) (c4 b4) (d4 c4) (d3 d4) (d2 d3) (d1 d2))
		(links in (b4 a4) (d4 e4))
	)
    (board-setup
        (Player
		   (Blue  b1 b2 b3)
		   (Green d1 d2 d3)
		)
	)
    (loss-condition (Player) repetition)
    (win-condition (Player)
		(and
		   (absolute-config Blue  (d1 d2 d3))
		   (absolute-config Green (b1 b2 b3))
		)
	)
)

(variant
    (title "E")
	(solution "Solutions\Swappers\E.zsg")
    (description "球可以任意移动，但不能越过其他子，且必须在撞墙或撞到其他子后停止。\\本关目标：交换两组球位置。目标位置在棋盘上有颜色标记。")
    (history "This is a simplified form of a puzzle invented by H.E. Dudeney and
        published in the Strand magazine in England in 1910.    Dudeney's version
        used numbered pieces (each piece has to be exchanged with the piece
        directly opposite) and requires 43 moves to solve.")
    (2D-defs)
	(board
        (image "images\Solitaire\EBd.bmp")
        (grid
            (start-rectangle 6 6 36 36) ; top-left position
            (dimensions
                ("a/b/c/d" (38 0)) ; columns
                ("5/4/3/2/1" (0 38)) ; rows
			)
		)
		(kill-positions a2 a3 a4 c2 c4 d2 d3 d4)
		(links blue-dir  (d1 c1) (c1 b1) (b1 b2) (b2 b3) (b3 b4) (b4 b5) (b5 c5) (c5 d5))
		(links green-dir (c1 d1) (b1 c1) (b2 b1) (b3 b2) (b4 b3) (b5 b4) (c5 b5) (d5 c5))
		(links in (b1 a1) (b3 c3) (b5 a5))
	)
    (board-setup
        (Player
		   (Blue  a5 b5 c5 d5)
		   (Green a1 b1 c1 d1)
		)
	)
    (loss-condition (Player) repetition)
    (win-condition (Player)
		(and
		   (absolute-config Blue  (a1 b1 c1 d1))
		   (absolute-config Green (a5 b5 c5 d5))
		)
	)
)

(variant
    (title "TriColor")
	(solution "Solutions\Swappers\TriColor.zsg")
    (description "球可以任意移动，但不能越过其他子，且必须在撞墙或撞到其他子后停止。\\本关目标：交换上下两组球位置。目标位置在棋盘上有颜色标记。")
    (history "") ;###
	(2D-defs)
    (board
        (image "images\Solitaire\TriColorBd.bmp")
        (grid
            (start-rectangle 6 6 36 36) ; top-left position
            (dimensions
                ("a/b/c/d/e" (38 0)) ; columns
                ("5/4/3/2/1" (0 38)) ; rows
			)
		)
		(kill-positions a2 a3 a4 c2 c4 d2 d3 d4 e2 e3 e4)
		(links blue-dir  (e1 d1) (d1 c1) (c1 b1) (b1 b2) (b2 b3) (b3 b4) (b4 b5) (b5 c5) (c5 d5) (d5 e5))
		(links green-dir (d1 e1) (c1 d1) (b1 c1) (b2 b1) (b3 b2) (b4 b3) (b5 b4) (c5 b5) (d5 c5) (e5 d5))
		(links in (b1 a1) (b3 c3) (b5 a5))
	)
    (piece
        (name Pink)
        (image Player "images\Solitaire\PinkMarble.bmp")
		(help "球必须沿横或竖方向无限移动至撞到什么东西为止。可以转弯。")
		(moves (far-slides))			
	)
    (board-setup
        (Player
		   (Blue  a5 b5 c5 d5)
		   (Green a1 c1 d1 e1)
		   (Pink e5)
		)
	)
    (loss-condition (Player) repetition)
    (win-condition (Player)
		(and
		   (absolute-config Blue  (a1 b1 c1 d1))
		   (absolute-config Green (a5 c5 d5 e5))
		   (absolute-config Pink (e1))
		)
	)
)

